<!DOCTYPE html>
<html>
 <head>
  <meta charset="utf-8">
  <title></title>
   
  <style type="text/css">
   *{
    margin: 0;
    padding: 0;
   }
   .magnifier .left{
    width: 240px;
    height: 150px;
    float: left;
    position: relative;
   }
   .magnifier .left img{
    width: 240px;
    height: 150px;
   }
   .magnifier .left .mask{
    width: 100%;
    height: 100%;
    position: absolute;
    left: 0;
    top: 0;
    background-color: black;
    opacity: 0.4;
   }
   .magnifier .float{
    width: 50px;
    height: 50px;
    background: hotpink;
    opacity: 0.5;
    position: absolute;
    left: 0;
    top: 0;
   }
   .magnifier .right{
    height: 200px;
    width: 200px;
    background-image: url(img/2.jpg) ;
    float: left;
    margin-left: 50px;
   }
  </style>
 </head>
 <body>
   
  <div class="magnifier">
   <div class="left">
    <img src="https://pic.qqtn.com/up/2018-1/15155479522444394.jpg" >
    <div class="float">
      
    </div>
    <div class="mask"></div>
   </div>
   <div class="right"></div>
  </div>
  <script type="text/javascript" charset="utf-8" src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
  <script>
   (function($){
    $.fn.extend({
     magnifier:function(){
      this.each(function(){
       var that=this;
       $('.left',this).mousemove(function (evt){
        var x=evt.offsetX;
        var y=evt.offsetY;
        var float=$('.float',this);
         
        x=x-float.width/2;
        y=y-float.height/2;
         
        if(x<0){
         x=0;
        }
        if(y<0){
         y=0;
        }
        if(x > $(this).width()-float.width()){
         x = $(this).width()-float.width();
        }
        if(y > $(this).height()-float.height()){
         y = $(this).height()-float.height();
        }
        float.css({
         left:x,
         top:y
        });
        $('.right',that).css({
         backgroundPosition:x*-4+'px' + y*-4+'px'
        })
       }).mouseover(function(){
         
       }).mouseout(function(){
         
       })
      });
     }
    })
   })(jQuery)
   $('.magnifier').magnifier();
  </script>
 </body>
</html>